<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../static/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
              
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>账户密码</legend>
</fieldset>
 
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">学号</label>
        <div class="layui-input-block">
            <input type="text" name="userNum" lay-verify="required" placeholder="请输入学号" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">旧密码</label>
        <div class="layui-input-block">
            <input type="password" name="userPwd" lay-verify="required" placeholder="请输入旧密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="userNewPwd1" lay-verify="pass" placeholder="请输入新密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">确认新密码</label>
        <div class="layui-input-block">
        <input type="password" name="userNewPwd2" lay-verify="pass" placeholder="请再次输入新密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="modify">修改</button>
        </div>
    </div>
</form>
 
          
<script src="../../static/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'layer'], function(){
  var form = layui.form
  ,layer = layui.layer;
  
  //自定义验证规则
  form.verify({
    userName: function(value){
      if(value.length < 2){
        return '用户至少得2个字符啊';
      }
    }
    ,pass: [
      /^[\S]{6,12}$/
      ,'密码必须6到12位，且不能出现空格'
    ]
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
});

layui.use(['layer', 'form'], function() {
      var layer = layui.layer,$ = layui.jquery,form = layui.form;
      form.on('submit(modify)', function(data) {
          $.ajax({
              url:"/account/security/{{user.userNum}}",
              data:data.field,
              dataType:'json',
              type:'post',
              success:function(data) {
                if (data.code === 0){
                  layer.msg('修改成功!');
                }else if (data.code === 1){
                  layer.msg('旧密码不正确!');
                }else if (data.code === 2){
                  layer.msg('两次输入的密码不一致!');
                }else if (data.code === 3){
                  layer.msg('修改失败!');
                }
                setTimeout(function() {
                      location.href = '/account/security/{{user.userNum}}';
                  }, 500);
              }
          });
          return false;
      });
    });
  

</script>

</body>
</html>